package com.dp.medical.medicalstore.model.obj.medicalstore;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.proxy.HibernateProxy;

import com.dp.medical.medicalstore.model.obj.medicalstore.iface.ISalesinvoicedetails;


/** 
 * Object mapping for hibernate-handled table: salesinvoicedetails.
 * @author autogenerated
 */

@Entity
@Table(name = "salesinvoicedetails", catalog = "medicalstore")
public class Salesinvoicedetails implements Cloneable, Serializable,  ISalesinvoicedetails {

	/** Serial Version UID. */
	private static final long serialVersionUID = -558955762L;

	/** Use a WeakHashMap so entries will be garbage collected once all entities 
		referring to a saved hash are garbage collected themselves. */
	private static final Map<Serializable, Serializable> SAVED_HASHES =
		Collections.synchronizedMap(new WeakHashMap<Serializable, Serializable>());
	
	/** hashCode temporary storage. */
	private volatile Serializable hashCode;
	

	/** Field mapping. */
	private Integer id = 0; // init for hibernate bug workaround
	/** Field mapping. */
	private Integer amount;
	/** Field mapping. */
	private Medicine medicineid;
	/** Field mapping. */
	private Double price;
	/** Field mapping. */
	private Salesinvoice salesinvoiceid;
 

	public Salesinvoicedetails() {}
	public Salesinvoicedetails (Integer id) {
		this.id = id;
	}
 
	public Salesinvoicedetails(Integer id, Integer amount, Medicine medicineid,
			Double price, Salesinvoice salesinvoiceid) {
		super();
		this.id = id;
		this.amount = amount;
		this.medicineid = medicineid;
		this.price = price;
		this.salesinvoiceid = salesinvoiceid;
	}


	/** Return the type of this class. Useful for when dealing with proxies.
	* @return Defining class.
	*/
	@Transient
	public Class<?> getClassType() {
		return Salesinvoicedetails.class;
	}
 

    /**
     * Return the value associated with the column: amount.
	 * @return A Integer object (this.amount)
	 */
	@Basic( optional = false )
	@Column( nullable = false  )
	public Integer getAmount() {
		return this.amount;
		
	}
	

  
    /**  
     * Set the value related to the column: amount.
	 * @param amount the amount value you wish to set
	 */
	public void setAmount(final Integer amount) {
		this.amount = amount;
	}

    /**
     * Return the value associated with the column: medicineid.
	 * @return A Medicine object (this.medicineid)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@Basic( optional = false )
	@JoinColumn(name = "MedicineId", nullable = false )
	public Medicine getMedicineid() {
		return this.medicineid;
		
	}
	

  
    /**  
     * Set the value related to the column: medicineid.
	 * @param medicineid the medicineid value you wish to set
	 */
	public void setMedicineid(final Medicine medicineid) {
		this.medicineid = medicineid;
	}

    /**
     * Return the value associated with the column: price.
	 * @return A Double object (this.price)
	 */
	@Basic( optional = false )
	@Column( nullable = false  )
	public Double getPrice() {
		return this.price;
		
	}
	

  
    /**  
     * Set the value related to the column: price.
	 * @param price the price value you wish to set
	 */
	public void setPrice(final Double price) {
		this.price = price;
	}

    /**
     * Return the value associated with the column: salesinvoiceid.
	 * @return A Salesinvoice object (this.salesinvoiceid)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@Basic( optional = false )
	@JoinColumn(name = "SalesInvoiceId", nullable = false )
	public Salesinvoice getSalesinvoiceid() {
		return this.salesinvoiceid;
		
	}
	

  
    /**  
     * Set the value related to the column: salesinvoiceid.
	 * @param salesinvoiceid the salesinvoiceid value you wish to set
	 */
	public void setSalesinvoiceid(final Salesinvoice salesinvoiceid) {
		this.salesinvoiceid = salesinvoiceid;
	}


   /**
    * Deep copy.
	* @return cloned object
	* @throws CloneNotSupportedException on error
    */
    @Override
    public Salesinvoicedetails clone() throws CloneNotSupportedException {
		
        final Salesinvoicedetails copy = (Salesinvoicedetails)super.clone();

		copy.setAmount(this.getAmount());
		copy.setMedicineid(this.getMedicineid());
		copy.setPrice(this.getPrice());
		copy.setSalesinvoiceid(this.getSalesinvoiceid());
		return copy;
	}
	


	/** Provides toString implementation.
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("amount: " + this.getAmount() + ", ");
		sb.append("price: " + this.getPrice() + ", ");
		return sb.toString();		
	}


	/** Equals implementation. 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;
		
		if ( this == aThat ) {
			 return true;
		}

		
		if (aThat instanceof HibernateProxy) {
 			// narrow down the proxy to the class we are dealing with.
 			try {
				proxyThat = ((HibernateProxy) aThat).getHibernateLazyInitializer().getImplementation(); 
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		   	}
		}
		if (aThat == null)  {
			 return false;
		}
		
		final Salesinvoicedetails that; 
		try {
			that = (Salesinvoicedetails) proxyThat;
			if ( !(that.getClassType().equals(this.getClassType()))){
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		} catch (ClassCastException e) {
				return false;
		}
		
		
		boolean result = true;
		result = result && (((this.getId() == null) && ( that.getId() == null)) || (this.getId() != null  && this.getId().equals(that.getId())));
		result = result && (((getAmount() == null) && (that.getAmount() == null)) || (getAmount() != null && getAmount().equals(that.getAmount())));
		result = result && (((getMedicineid() == null) && (that.getMedicineid() == null)) || (getMedicineid() != null && getMedicineid().getId().equals(that.getMedicineid().getId())));	
		result = result && (((getPrice() == null) && (that.getPrice() == null)) || (getPrice() != null && getPrice().equals(that.getPrice())));
		result = result && (((getSalesinvoiceid() == null) && (that.getSalesinvoiceid() == null)) || (getSalesinvoiceid() != null && getSalesinvoiceid().getId().equals(that.getSalesinvoiceid().getId())));	
		return result;
	}
	
	/** Calculate the hashcode.
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if ( this.hashCode == null ) {
			synchronized ( this ) {
				if ( this.hashCode == null ) {
					Serializable newHashCode = null;

					if ( getId() != null ) {
					newHashCode = SAVED_HASHES.get( getId() );
					}
					
					if ( newHashCode == null ) {
						if ( getId() != null ) {
							newHashCode = getId();
						} else {

						}
					}
					
					this.hashCode = newHashCode;
				}
			}
		}
	return (Integer) this.hashCode;
	}


    /**
     * Return the value associated with the column: id.
	 * @return A Integer object (this.id)
	 */
    @Id 
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Basic( optional = false )
	@Column( name = "id", nullable = false  )
	public Integer getId() {
		return this.id;
	}


	@Override
	public void setId(Integer id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ( (this.id == null || this.id == 0) &&
				(id != null) &&
				(this.hashCode != null) ) {
		SAVED_HASHES.put( id, this.hashCode );
		}
		this.id = id;
	}
	

	
}
